package info.manxi;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.PoisonPill;
import akka.actor.Props;
import akka.actor.Terminated;

import java.math.BigDecimal;
import java.util.Optional;

/**
 * <pre>
 * <b>Description</b>
 * </pre>
 * <pre>
 * 创建时间 2019-11-25 15:28
 * 所属工程： akka-actor-101  </pre>
 *
 * @author sheldon yhid: 80752866
 */
public class Boy extends AbstractActor {
    static Props props() {
        return Props.create(Boy.class, Boy::new);
    }

    @Override
    public void preStart() throws Exception {
        print("preStart");
        super.preStart();
    }

    @Override
    public void postStop() throws Exception {
        super.postStop();
        print("postStop");
    }

    @Override
    public void preRestart(Throwable reason, Optional<Object> message) throws Exception {
        print("preRestart");
        super.preRestart(reason, message);
    }

    @Override
    public void postRestart(Throwable reason) throws Exception {
        super.postRestart(reason);
        print("postRestart");
    }

    @Override
    public Receive createReceive() {
        return receiveBuilder()
                .matchAny(msg -> {
                    print("我收到了" + getSender() + "的消息：" + msg);
                    getSelf().tell("", getSelf());
                    throw new RuntimeException("kill me");
                })
                .build();
    }

    private void print(Object obj) {
        System.out.println("男孩说：" + obj);
    }
}
